cc.Class({
    extends: cc.Component,
    properties: {
        TiledMapRoot:cc.Node,
        leftBtn:cc.Node,
        rightBtn:cc.Node,
        topBtn:cc.Node,
        bottonBtn:cc.Node,
        p_leftBtn:cc.Node,
        p_rightBtn:cc.Node,
        p_topBtn:cc.Node,
        p_bottonBtn:cc.Node,
        LeftMoveState:{
            get(){
                if(!this._LeftMove)this._LeftMove=false;
                return this._LeftMove;
            },
            set(value)
            {
                this._LeftMove = value;
            }
        },
        RightMoveState:{
            get(){
                if(!this._RightMove)this._RightMove=false;
                return this._RightMove;
            },
            set(value)
            {
                this._RightMove = value;
            }
        },
        TopMoveState:{
            get(){
                if(!this._TopMove)this._TopMove=false;
                return this._TopMove;
            },
            set(value)
            {
                this._TopMove = value;
            }
        },
        BottomMoveState:{
            get(){
                if(!this._BottomMove)this._BottomMove=false;
                return this._BottomMove;
            },
            set(value)
            {
                this._BottomMove = value;
            }
        },
        PLeftMoveState:{
            get(){
                if(!this._PLeftMoveState)this._PLeftMoveState=false;
                return this._PLeftMoveState;
            },
            set(value)
            {
                this._PLeftMoveState = value;
            }
        },
        PRightMoveState:{
            get(){
                if(!this._PRightMove)this._PRightMove=false;
                return this._PRightMove;
            },
            set(value)
            {
                this._PRightMove = value;
            }
        },
        PTopMoveState:{
            get(){
                if(!this._PTopMoveState)this._PTopMoveState=false;
                return this._PTopMoveState;
            },
            set(value)
            {
                this._PTopMoveState = value;
            }
        },
        PBottomMoveState:{
            get(){
                if(!this._PBottomMoveState)this._PBottomMoveState=false;
                return this._PBottomMoveState;
            },
            set(value)
            {
                this._PBottomMoveState = value;
            }
        }
    },
    onLoad ()
    {
        this.leftBtn.on("touchstart",this.OnLeftStart,this);
        this.rightBtn.on("touchstart",this.OnRightStart,this);
        this.topBtn.on("touchstart",this.OnTopStart,this);
        this.bottonBtn.on("touchstart",this.OnBottonStart,this);

        this.leftBtn.on("touchend",this.OnLeftEnd,this);
        this.rightBtn.on("touchend",this.OnRightEnd,this);
        this.topBtn.on("touchend",this.OnTopEnd,this);
        this.bottonBtn.on("touchend",this.OnBottonEnd,this);

        this.p_leftBtn.on("touchstart",this.On_LeftStart,this);
        this.p_rightBtn.on("touchstart",this.On_RightStart,this);
        this.p_topBtn.on("touchstart",this.On_TopStart,this);
        this.p_bottonBtn.on("touchstart",this.On_BottonStart,this);

        this.p_leftBtn.on("touchend",this.On_LeftEnd,this);
        this.p_rightBtn.on("touchend",this.On_RightEnd,this);
        this.p_topBtn.on("touchend",this.On_TopEnd,this);
        this.p_bottonBtn.on("touchend",this.On_BottonEnd,this);

        setInterval(this.uppos.bind(this), 100);

    },
    uppos()
    {
        if(this.LeftMoveState)
        {
            this.TiledMapRoot.getComponent("UI-TiledMap").MoveTiledMap(1,0)
        }
        if(this.RightMoveState)
        {
            this.TiledMapRoot.getComponent("UI-TiledMap").MoveTiledMap(-1,0);
        }
        if(this.TopMoveState)
        {
            this.TiledMapRoot.getComponent("UI-TiledMap").MoveTiledMap(0,-1);
        }
        if(this.BottomMoveState)
        {
            this.TiledMapRoot.getComponent("UI-TiledMap").MoveTiledMap(0,1);
        }

        if(this.PLeftMoveState)
        {
            this.TiledMapRoot.getComponent("UI-TiledMap").SelectTiledItem(1,0)
        }
        if(this.PRightMoveState)
        {
            this.TiledMapRoot.getComponent("UI-TiledMap").SelectTiledItem(-1,0);
        }
        if(this.PTopMoveState)
        {
            this.TiledMapRoot.getComponent("UI-TiledMap").SelectTiledItem(0,-1);
        }
        if(this.PBottomMoveState)
        {
            this.TiledMapRoot.getComponent("UI-TiledMap").SelectTiledItem(0,1);
        }

    },
    /********************** Left Event *********************************** */
    On_LeftStart(event)
    {
        this.PLeftMoveState=true;
    },
    On_LeftEnd(event)
    {
        this.PLeftMoveState=false;
    },
    /********************** Right Event *********************************** */
    On_RightStart(event)
    {
        this.PRightMoveState=true;
    },
    On_RightEnd(event)
    {
        this.PRightMoveState=false;
    },
    /********************** Top Event *********************************** */
    On_TopStart(event)
    {
        this.PTopMoveState=true;
    },
    On_TopEnd(event)
    {
        this.PTopMoveState=false;
    },
    /********************** Botton Event *********************************** */
    On_BottonStart(event)
    {
        this.PBottomMoveState=true;
    },
    On_BottonEnd(event)
    {
        this.PBottomMoveState=false;
    },

    /********************** Left Event *********************************** */
    OnLeftStart(event)
    {
        this.LeftMoveState=true;
    },
    OnLeftEnd(event)
    {
        this.LeftMoveState=false;
    },
    /********************** Right Event *********************************** */
    OnRightStart(event)
    {
        this.RightMoveState=true;
    },
    OnRightEnd(event)
    {
        this.RightMoveState=false;
    },
    /********************** Top Event *********************************** */
    OnTopStart(event)
    {
        this.TopMoveState=true;
    },
    OnTopEnd(event)
    {
        this.TopMoveState=false;
    },
    /********************** Botton Event *********************************** */
    OnBottonStart(event)
    {
        this.BottomMoveState=true;
    },
    OnBottonEnd(event)
    {
        this.BottomMoveState=false;
    },
   
});
